<?php
class CompEconomic extends AppModel
{
	var $name='CompEconomic';
	var $primaryKey = 'id'; 
	 var $hasMany = array (
    		'Attachment' => array (
	 		'conditions' => array("Attachment.is_deleted='0'"),
			'className' => 'Attachment',
			'foreignKey' => 'pid'
			)
	); 
	var $belongsTo = array(
			'Company'=>array(
				'conditions' => array("Company.is_deleted='0'"),
				'className'=>'Company',
				'foreignKey'=>'cid'	
			)
	);
	
	function findRecentdataGroupByCid($where=''){
		if($where!=""){
			 $where.=" and companies.is_deleted='0' and comp_economics.is_deleted='0' ";
			$maxcreatedsql = ' SELECT comp_economics.cid,comp_economics.created,comp_economics.general_income FROM  comp_economics  INNER JOIN companies on companies.id = comp_economics.cid where '. $where.' GROUP BY cid';
		}else{
			$maxcreatedsql = " SELECT comp_economics.cid,comp_economics.created,comp_economics.general_income FROM  comp_economics INNER JOIN companies on companies.id = comp_economics.cid where companies.is_deleted='0' and comp_economics.is_deleted='0'   GROUP BY cid";   
		}

		$maxcreateddata = $this->query($maxcreatedsql);
		return $maxcreateddata;
	}
	
	
}
?>